package com.freesun.shop.entity;

import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

public class Object2Long extends JsonSerializer<List<Object>>{
	/**
	 * List<Object>-> 使用json 显示时，我们可以让它称为一个别的类型
	 */
	@Override
	public void serialize(List<Object> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		if(value!=null&&!value.isEmpty()) {
			long []valueLong = new long[value.size()];
			for (int i = 0; i < valueLong.length; i++) {
				valueLong[i] = Long.valueOf(value.get(i).toString());
			}
			gen.writeArray(valueLong, 0, valueLong.length);
		}else {
			gen.writeArray(new long[0], 0, 0);
		}
	}

}
